package com.teach;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * <pre>
 * -
 * Author : J.L.Zhou
 * E-Mail : 2233875735@qq.com
 * Tel : 151 1104 7708
 * Date : 2021-04-13 14:22
 * Version : 1.0
 * Copyright 2021 jlzhou.top Inc. All rights reserved.
 * Warning: this content is only for internal circulation of the company.
 *          It is forbidden to divulge it or use it for other commercial purposes.
 * </pre>
 **/
public class Demo04 {

  public static void main(String[] args) {
    double d1 = 0.123456789012345678901;
    System.out.println(d1);
    double d2 = 123456789012345678901.0;
    System.out.println(d2);
    BigDecimal bd1 = new BigDecimal("0.123456789012345678901");
    BigDecimal bd2 = new BigDecimal("123456789012345678901.0");
    System.out.println(bd1);
    System.out.println(bd2);
    int i1 = bd1.intValue();
    double d3 = bd1.doubleValue();
    System.out.println(d2+1000);
    BigDecimal bd3 = bd2.add(new BigDecimal("1000"));
    System.out.println(bd3);
    BigDecimal bd4 = new BigDecimal("1");
    BigDecimal bd5 = new BigDecimal("3");
//    BigDecimal bd6 = bd4.divide(bd5);//ArithmeticException: Non-terminating decimal expansion; no exact represent
    BigDecimal bd6 = bd4.divide(bd5,3, RoundingMode.HALF_UP);//四舍五入保留3位
    System.out.println(bd6);
  }
}
